package com.ruoyi.web.controller.school;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.school.domain.PacDepartment;
import com.ruoyi.school.service.PacDepartmentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/school/department")
public class PacDepartmentController extends BaseController {
    @Resource
    private PacDepartmentService pacDepartmentService;

    /**
     * 院系列表查询（关联学院）
     */
    @GetMapping("/list")
    public TableDataInfo list(PacDepartment pacDepartment) {
        startPage();
        List<PacDepartment> list = pacDepartmentService.getList(pacDepartment);
        return getDataTable(list);
    }

    /**
     * 院系详情查询（含学院信息）
     */
    @GetMapping("/details")
    public AjaxResult details(PacDepartment pacDepartment) {
        PacDepartment details = pacDepartmentService.getDetails(pacDepartment);
        return success(details);
    }

    /**
     * 新增院系（需关联学院）
     */
    @Log(title = "院系（关联学院）", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody PacDepartment pacDepartment) {
        boolean add = pacDepartmentService.add(pacDepartment);
        return success(add);
    }

    /**
     * 修改院系（含学院关联调整）
     */
    @Log(title = "院系（关联学院）", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult update(@RequestBody PacDepartment pacDepartment) {
        boolean update = pacDepartmentService.edit(pacDepartment);
        return success(update);
    }

    /**
     * 删除院系（需确认学院关联关系）
     */
    @Log(title = "院系（关联学院）", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete")
    public AjaxResult delete(PacDepartment pacDepartment) {
        boolean delete = pacDepartmentService.delete(pacDepartment);
        return success(delete);
    }

    /**
     * 查询所有院系（含学院信息）
     */
    @ApiOperation("所有院系（含学院信息）")
    @GetMapping("/all")
    public AjaxResult all(PacDepartment pacDepartment) {
        List<PacDepartment> list = pacDepartmentService.getAllList(pacDepartment);
        return success(list);
    }

    /**
     * 根据 学院查询所有院系
     */
    @ApiOperation("根据 学院查询所有院系")
    @GetMapping("/listByCollege")
    public AjaxResult listByCollege(PacDepartment pacDepartment) {
        List<PacDepartment> list = pacDepartmentService.getList(pacDepartment);
        return success(list);
    }
}